package com.jvyou.mybatis.builder.tags;

import com.jvyou.mybatis.session.Configuration;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dom4j.Element;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/8 18:22
 * @Description 数据源相关配置
 */
@Deprecated
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataSourceNode implements XmlConfigNode {

    /*数据源的类型，eg：POOLED*/
    private String type;

    /*数据源的连接地址*/
    private String url;

    /*数据源的用户名*/
    private String username;

    /*数据源的密码*/
    private String password;

    /*数据源的驱动*/
    private String driver;

    /*数据源的配置节点*/
    private Element element;

    public DataSourceNode(Element element) {
        this.element = element;
    }

    @Override
    public Configuration apply(Configuration configuration) {
        Element urlElement = (Element) element.elements("url").get(0);
        Element usernameElement = (Element) element.elements("username").get(0);
        Element passwordElement = (Element) element.elements("password").get(0);
        Element driverElement = (Element) element.elements("driver").get(0);
        this.url = urlElement.attributeValue("value").trim();
        this.username = usernameElement.attributeValue("value").trim();
        this.password = passwordElement.attributeValue("value").trim();
        this.driver = driverElement.attributeValue("value").trim();
        return configuration;
    }
}
